import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false



//配置axios
import axios from '@/utils/request';
Vue.prototype.$axios = axios;

//配置elementUI的环境
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);//引入内容


//拦截器的定义
router.beforeEach((to, from, next) => {
  console.log(to);
  //判断当前要访问的页面不是登陆页面
  if (to.path !== "/admin/login" && to.path.indexOf("/admin") > -1) {
    //获取token值
    let token = sessionStorage.getItem("token");
    //判断token值，token值如果为空
    if (token == null) {
      //跳转到登陆页面去
      next("/admin/login");
    }
  }
  //先使用next()
  next();
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
